package com.gxa.ehome.proxy;

import com.gxa.ehome.service.SysUserService;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

@Component("InvocationHandler")
public class SysUserServiceInvocationHandler implements InvocationHandler {

//    通过代理实现目标日志自动记录
//企业中对于日志类型 业务日志 操作日志 error日志




    private SysUserService sysUserService=null;

    public SysUserServiceInvocationHandler(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //操作前的记录:
        System.out.println("执行方法:"+method.getName()+",传递的参数是"+ Arrays.toString(args));
        Object invoke = method.invoke(sysUserService, args);
        //操作后的记录:
        System.out.println("方法成功执行,返回结果是:"+invoke);
        return invoke;

//        try{
//
//        }catch(Exeption e){
//
//        }finally{
//
//
//        }
    }
}
